﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Infragistics.Win.UltraWinGrid;
using WHC.OrderWater.Commons;

namespace CKNetFrameWork
{
    public partial class Frm_ClassMgr : DockContent
    {
        private TrainingDB.BLL.CK_ClassTab m_bllCK_ClassTab = new TrainingDB.BLL.CK_ClassTab();
        private TrainingDB.BLL.CK_SchoolTab m_bllCK_SchoolTab = new TrainingDB.BLL.CK_SchoolTab();
        private TrainingDB.BLL.CK_TeacherTab m_bllCK_TeacherTab = new TrainingDB.BLL.CK_TeacherTab();
        private TrainingDB.BLL.CK_CourseTab m_bllCK_CourseTab = new TrainingDB.BLL.CK_CourseTab();
        private TrainingDB.BLL.CK_RecvMoneyWayTab m_bllCK_RecvMoneyWayTab = new TrainingDB.BLL.CK_RecvMoneyWayTab();
        private int m_nDelIndex = -1;
        private bool m_bInsertFlag = false;
        private Dictionary<string, string> m_dicColName2AliasName = new Dictionary<string, string>();
        private Dictionary<string, string> m_dicColAliasName2Name = new Dictionary<string, string>();

        public Frm_ClassMgr()
        {
            InitializeComponent();
        }

        private void InitColumnWidth()
        {

            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                ultraGrid1.DisplayLayout.Bands[0].Columns[m_dicColName2AliasName[strTemp]].Width = Frm_Main.m_nDfuColWidth; 

            }
            //ultraGrid1.DisplayLayout.Bands[0].Columns["时段"].Width = 80;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["星期设置"].Width = 90;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["缺省学时"].Width = 50;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["教师课时费标准"].Width = 60;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["是否排除节假日"].Width = 60;


        }
        private void ShowAllRecordInDataGridView(string strWhere)
        {
            ultraGrid1.DataSource = null;
            DataSet ds = m_bllCK_ClassTab.GetList(strWhere);
            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                ds.Tables[0].Columns[strTemp].ColumnName = m_dicColName2AliasName[strTemp];
      
            }

            DataSet dsTemp = m_bllCK_SchoolTab.GetOnlyList("");

            this.ultraDropDownDep.DataSource = dsTemp.Tables[0];
            this.ultraDropDownDep.DisplayMember = "校区名称";
            this.ultraDropDownDep.ValueMember = "CK_SchoolTabID";
            this.ultraDropDownDep.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownDep.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownDep.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownDep.DisplayLayout.Bands[0].Columns["校区名称"].Hidden = false;


            dsTemp = m_bllCK_RecvMoneyWayTab.GetList("");
            this.ultraDropDownFeeMode.DataSource = dsTemp.Tables[0];
            this.ultraDropDownFeeMode.DisplayMember = "CK_RecvMoneyWayName";
            this.ultraDropDownFeeMode.ValueMember = "CK_RecvMoneyWayTabID";
            this.ultraDropDownFeeMode.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownFeeMode.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownFeeMode.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownFeeMode.DisplayLayout.Bands[0].Columns["CK_RecvMoneyWayName"].Hidden = false;


            dsTemp = m_bllCK_TeacherTab.GetOnlyList("");

            this.ultraDropDownT1.DataSource = dsTemp.Tables[0];
            this.ultraDropDownT1.DisplayMember = "教师名称";
            this.ultraDropDownT1.ValueMember = "CK_TeacherTabID";
            this.ultraDropDownT1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownT1.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownT1.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownT1.DisplayLayout.Bands[0].Columns["教师名称"].Hidden = false;

            dsTemp = m_bllCK_TeacherTab.GetOnlyList("");

            this.ultraDropDownT2.DataSource = dsTemp.Tables[0];
            this.ultraDropDownT2.DisplayMember = "教师名称";
            this.ultraDropDownT2.ValueMember = "CK_TeacherTabID";
            this.ultraDropDownT2.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownT2.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownT2.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownT2.DisplayLayout.Bands[0].Columns["教师名称"].Hidden = false;

            dsTemp = m_bllCK_CourseTab.GetOnlyList("");

            this.ultraDropDownCourse.DataSource = dsTemp.Tables[0];
            this.ultraDropDownCourse.DisplayMember = "课程名称";
            this.ultraDropDownCourse.ValueMember = "CK_CourseTabID";
            this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns["课程名称"].Hidden = false;


            ultraGrid1.DataSource = ds.Tables[0];
            ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["校区名称"].ValueList = this.ultraDropDownDep;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["讲师姓名"].ValueList = this.ultraDropDownT1;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["班主任"].ValueList = this.ultraDropDownT2;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["课程名称"].ValueList = this.ultraDropDownCourse;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["学费收费模式"].ValueList = this.ultraDropDownFeeMode;

        }
        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecordInDataGridView("");
        }

        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            InitColumnWidth();
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);
        }
        private void AddNewRow()
        {
            if (Frm_Main.CheckPerm(this.Text, "增加"))
            {
                UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
            else
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
        private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                int nIndex = ultraGrid1.ActiveRow.Index;
                if (nIndex == -1)
                {
                    List<object> lstO = this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.All.ToList();

                    string strColumnName;
                    string strColumnValue;
                    SearchCondition condition = new SearchCondition();
                    foreach (object o in lstO)
                    {
                        ColumnFilter cf = (ColumnFilter)o;
                        strColumnName = cf.Column.Key;
                        strColumnValue = cf.FilterConditions.Count > 0 ? ((FilterCondition)cf.FilterConditions.All[0]).CompareValue.ToString() : "";
                        if (strColumnValue != "")
                        {
                            condition = condition.AddCondition(m_dicColAliasName2Name[strColumnName], strColumnValue, SqlOperator.Equal);
                        }
                    }

                    string filter = condition.BuildConditionSql();
                    filter = filter.Replace("Where", "");
                    ShowAllRecordInDataGridView(filter);
                }
            }
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {

                if (!m_bInsertFlag)
                {
                    AddNewRow();
                    //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                    //  row.Cells[2] = DateTime.Parse("1900-01-01");
                }
            }
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex < ultraGrid1.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }

        }

        private bool AddGoodsDetail(int nRowIndex)
        {

            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                TrainingDB.Model.CK_ClassTab modelCK_ClassTab = new TrainingDB.Model.CK_ClassTab();

                modelCK_ClassTab.CK_SchoolTabID = Convert.ToInt32(CurrentUGR.Cells["校区名称"].Value.ToString(), 10);
                modelCK_ClassTab.CK_OperUserID = Frm_Main.m_nLoginUserId;
                modelCK_ClassTab.CK_TeacherTabID = Convert.ToInt32(CurrentUGR.Cells["讲师姓名"].Value.ToString());
                modelCK_ClassTab.CK_TeacherTabID2 = Convert.ToInt32(CurrentUGR.Cells["班主任"].Value.ToString());
                modelCK_ClassTab.CK_CourseTabID = Convert.ToInt32(CurrentUGR.Cells["课程名称"].Value.ToString());
                modelCK_ClassTab.CK_RecvMoneyWayTabID = Convert.ToInt32(CurrentUGR.Cells["学费收费模式"].Value.ToString());

                modelCK_ClassTab.chargeStd = Convert.ToDecimal(CurrentUGR.Cells["学费收费标准"].Value.ToString());
                modelCK_ClassTab.CK_className = CurrentUGR.Cells["班级名称"].Value.ToString();
                modelCK_ClassTab.hourFeeStd = Convert.ToDecimal(CurrentUGR.Cells["课时费"].Value.ToString());
                modelCK_ClassTab.isEnd = CurrentUGR.Cells["是否结束"].Value.ToString();
                modelCK_ClassTab.classMemo = CurrentUGR.Cells["备注"].Value.ToString();
                modelCK_ClassTab.planStdtQtty = Convert.ToInt32(CurrentUGR.Cells["计划人数"].Value.ToString());
                modelCK_ClassTab.realStdtQtty = Convert.ToInt32(CurrentUGR.Cells["实际人数"].Value.ToString());
                modelCK_ClassTab.currStdtQtty = Convert.ToInt32(CurrentUGR.Cells["当前人数"].Value.ToString());

     


                int nId = m_bllCK_ClassTab.Add(modelCK_ClassTab);

                ShowAllRecordInDataGridView("");
                MessageBox.Show("添加记录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        private void InitNewAddRowValue(int nIndex)
        {
            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];

            CurrentUGR.Cells["校区名称"].Value = 1;
            CurrentUGR.Cells["录入人"].Value = Frm_Main.m_nLoginUserId;
            CurrentUGR.Cells["讲师姓名"].Value = m_bllCK_TeacherTab.GetMaxId() - 1;
            CurrentUGR.Cells["班主任"].Value = CurrentUGR.Cells["讲师姓名"].Value;
            CurrentUGR.Cells["课程名称"].Value = 1;
            CurrentUGR.Cells["学费收费模式"].Value = 1;
            CurrentUGR.Cells["学费收费标准"].Value = 0;
            CurrentUGR.Cells["班级名称"].Value = "";
            CurrentUGR.Cells["课时费"].Value = 0;
            CurrentUGR.Cells["是否结束"].Value = "否";

            CurrentUGR.Cells["备注"].Value = "";
            CurrentUGR.Cells["计划人数"].Value = 0;
            CurrentUGR.Cells["实际人数"].Value = 0;
            CurrentUGR.Cells["当前人数"].Value = 0;
     

            if (m_bInsertFlag)
            {
                ultraGrid1.Rows[nIndex].Cells[0].Activation = Activation.ActivateOnly;
                m_bInsertFlag = false;
                AddGoodsDetail(nIndex);

            }

        }

        private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
        {
            ultraGrid1.Rows[e.Row.Index].Cells[1].IgnoreRowColActivation = true;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activation = Activation.AllowEdit;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activate();
            ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
            
            m_bInsertFlag = true;
            InitNewAddRowValue(e.Row.Index);
        }

        private bool ModifyGoodsDetail(int nRowIndex)
        {

            try
            {
                if (!Frm_Main.CheckPerm(this.Text, "修改"))
                {
                    MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_ClassTab modelCK_ClassTab = m_bllCK_ClassTab.GetModel(nSelectFinRecvMoneyDetailTab_NewID);

                
                modelCK_ClassTab.chargeStd = Convert.ToDecimal(CurrentUGR.Cells["学费收费标准"].Value.ToString());
                modelCK_ClassTab.CK_className = CurrentUGR.Cells["班级名称"].Value.ToString();
                modelCK_ClassTab.hourFeeStd = Convert.ToDecimal(CurrentUGR.Cells["课时费"].Value.ToString());
                modelCK_ClassTab.isEnd = CurrentUGR.Cells["是否结束"].Value.ToString();
                modelCK_ClassTab.classMemo = CurrentUGR.Cells["备注"].Value.ToString();
                modelCK_ClassTab.planStdtQtty = Convert.ToInt32(CurrentUGR.Cells["计划人数"].Value.ToString());
                modelCK_ClassTab.realStdtQtty = Convert.ToInt32(CurrentUGR.Cells["实际人数"].Value.ToString());
                modelCK_ClassTab.currStdtQtty = Convert.ToInt32(CurrentUGR.Cells["当前人数"].Value.ToString());

                string strBGH = CurrentUGR.Cells["校区名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassTab.CK_SchoolTabID = Convert.ToInt32(CurrentUGR.Cells["校区名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_SchoolTab.GetList("CK_SchoolTabName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassTab.CK_SchoolTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_SchoolTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["学费收费模式"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassTab.CK_RecvMoneyWayTabID = Convert.ToInt32(CurrentUGR.Cells["学费收费模式"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_RecvMoneyWayTab.GetList("CK_RecvMoneyWayName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassTab.CK_RecvMoneyWayTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_RecvMoneyWayTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["讲师姓名"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassTab.CK_TeacherTabID = Convert.ToInt32(CurrentUGR.Cells["讲师姓名"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_TeacherTab.GetList("CK_TeacherName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassTab.CK_TeacherTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_TeacherTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["班主任"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassTab.CK_TeacherTabID2 = Convert.ToInt32(CurrentUGR.Cells["班主任"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_TeacherTab.GetList("CK_TeacherName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassTab.CK_TeacherTabID2 = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_TeacherTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["课程名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_ClassTab.CK_CourseTabID = Convert.ToInt32(CurrentUGR.Cells["课程名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_CourseTab.GetList("CK_course = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_ClassTab.CK_CourseTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_CourseTabID"].ToString(), 10);
                    }
                }


                m_bllCK_ClassTab.Update(modelCK_ClassTab);

              //  MessageBox.Show("修改教室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            m_nDelIndex = ultraGrid1.ActiveRow.Index;
        }

        private void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid1.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;
                    if (!AddGoodsDetail(e.Row.Index))
                        e.Cancel = true;



                }
                else//修改
                {

                    ModifyGoodsDetail(e.Row.Index);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid1_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_ClassTab modelCK_ClassTabOld = m_bllCK_ClassTab.GetModel(nSelectFinRecvMoneyDetailTab_NewID);

                if (modelCK_ClassTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllCK_ClassTab.Delete(nSelectFinRecvMoneyDetailTab_NewID);



                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void 增加一行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!m_bInsertFlag)
            {
                AddNewRow();
                //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
        }

        private void 删除一行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Frm_Main.CheckPerm(this.Text, "删除"))
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                DialogResult dr = MessageBox.Show("确实要删除该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                if (ultraGrid1.ActiveRow != null)
                {

                    ultraGrid1.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void Frm_ClassRoom_Load_1(object sender, EventArgs e)
        {
            //DateTime dt = DateTime.Now.Date;
            //DateTime dt2 = dt.AddDays(1);
            //DayOfWeek d = dt.DayOfWeek;
            m_dicColName2AliasName.Add("CK_SchoolTabName", "校区名称");
            m_dicColName2AliasName.Add("Name", "录入人");
            m_dicColName2AliasName.Add("CK_TeacherName", "讲师姓名");
            m_dicColName2AliasName.Add("CK_TeacherName2", "班主任");
            m_dicColName2AliasName.Add("CK_course", "课程名称");
            
            m_dicColName2AliasName.Add("CK_className", "班级名称");
            m_dicColName2AliasName.Add("CK_RecvMoneyWayName", "学费收费模式");
            m_dicColName2AliasName.Add("chargeStd", "学费收费标准");
            m_dicColName2AliasName.Add("hourFeeStd", "课时费");
            m_dicColName2AliasName.Add("isEnd", "是否结束");
        
            m_dicColName2AliasName.Add("planStdtQtty", "计划人数");
            m_dicColName2AliasName.Add("realStdtQtty", "实际人数");
            m_dicColName2AliasName.Add("currStdtQtty", "当前人数");
            m_dicColName2AliasName.Add("classMemo", "备注");
            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                //ds.Tables[0].Columns[strTemp].ColumnName = m_dicColName2AliasName[strTemp];
                m_dicColAliasName2Name.Add(m_dicColName2AliasName[strTemp], strTemp);
            }
        }

        private void buttonExportExcel_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }

        private void rectangleShape1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

    }
}


